<?php
/**
 * Created by PhpStorm.
 * User: davin
 * Date: 14-10-19
 * Time: 下午12:03
 *
 * 购物车类
 */

use LaravelBook\Ardent\Ardent;

class OrderFood extends Ardent{


    public static $relationsData = array(
        'order' => array(self::BELONGS_TO, 'Order', 'foreignKey' => 'order_id', 'otherKey' => 'id'),
        'foods' => array(self::BELONGS_TO_MANY, 'Food', 'table' => 'package_foods', "foreignKey"=> 'package_id',"otherKey"=> 'food_id'),
        'thumbs' => array(self::MORPH_MANY, 'Thumb', 'name' => 'thumbable'),
    );

    /**
     * 保存该餐品的相册
     * @param $thumbs
     */
    public function saveThumb($thumbs){

        if($thumbs){
            $this->thumbs()->delete();
            foreach ($thumbs as $thumb){
                $newThumb = new Thumb();
                $newThumb->path = $thumb->path;
                $this->thumbs()->save($newThumb);
            }
        }
    }
}
